package com.ihg.hiex.admin.dao.session;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.ihg.hiex.entity.session.during.SessionCompetencyScore;
import com.ihg.hiex.entity.session.during.SessionExercise;
import com.ihg.hiex.entity.session.during.SessionInBasket;

/**
 * 
 * @author dan
 *
 */
@Dao("hibernate")
public interface SessionCompetencyDao {
    
    /**
     * 
     * @param sessionExercises
     * @param sessionInBasket
     * @return
     */
    @Query("FROM SessionCompetencyScore WHERE disabled = false AND (sessionExercise in(:sessionExercises) OR sessionInBasket = :sessionInBasket)")
    public List<SessionCompetencyScore> list(@Variable("sessionExercises") List<SessionExercise> sessionExercises, @Variable("sessionInBasket") SessionInBasket sessionInBasket);

    /**
     * 
     * @param sessionExercises
     * @param sessionInBasket
     * @param names
     * @return
     */
    @Query("FROM SessionCompetencyScore WHERE disabled = false AND (sessionExercise in(:sessionExercises) OR sessionInBasket = :sessionInBasket) AND sessionCompetency.name in(:names)")
    public List<SessionCompetencyScore> list(@Variable("sessionExercises") List<SessionExercise> sessionExercises, @Variable("sessionInBasket") SessionInBasket sessionInBasket, @Variable("names") String[] names);

    /**
     * 
     * @param sessionExercise
     * @param name
     * @return
     */
    @Query("FROM SessionCompetencyScore WHERE disabled = false AND sessionExercise = :sessionExercise AND sessionCompetency.name = :name")
    public SessionCompetencyScore load(@Variable("sessionExercise") SessionExercise sessionExercise, @Variable("name") String name);

    /**
     * 
     * @param sessionInBasket
     * @param name
     * @return
     */
    @Query("FROM SessionCompetencyScore WHERE disabled = false AND sessionInBasket = :sessionInBasket AND sessionCompetency.name = :name")
    public SessionCompetencyScore load(@Variable("sessionInBasket") SessionInBasket sessionInBasket, @Variable("name") String name);

    /**
     * 
     * @param sessionExercise
     * @param finish
     * @return
     */
    @Query("FROM SessionCompetencyScore WHERE disabled = false AND sessionExercise = :sessionExercise AND finish = :finish ORDER BY sorting")
    public SessionCompetencyScore load(@Variable("sessionExercise") SessionExercise sessionExercise, @Variable("finish") boolean finish);

    /**
     * 
     * @param sessionExercise
     * @param finish
     * @return
     */
    @Query("SELECT COUNT(*) FROM SessionCompetencyScore WHERE disabled = false AND sessionExercise = :sessionExercise AND finish = :finish")
    public int count(@Variable("sessionExercise") SessionExercise sessionExercise, @Variable("finish") boolean finish);

    /**
     * 
     * @param sessionInBasket
     * @param finish
     * @return
     */
    @Query("SELECT COUNT(*) FROM SessionCompetencyScore WHERE disabled = false AND sessionInBasket = :sessionInBasket AND finish = :finish")
    public int count(@Variable("sessionInBasket") SessionInBasket sessionInBasket, @Variable("finish") boolean finish);

}
